package com.ali.resource.ShareTools;


import org.springframework.stereotype.Component;

import java.io.File;
import java.text.SimpleDateFormat;

@Component
public class BasicTools {

    public static String currentTime(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd.HH-mm-ss");
        long l = System.currentTimeMillis();
        return simpleDateFormat.format(l);
    }


    public static File setFIlePath(String fileName){
        String osName = System.getProperty("os.name");
        String home = System.getProperty("user.home");

        File file = new File(fileName);

        if (osName.toLowerCase().contains("windows")) {
            file = new File(home + "\\Downloads\\" + BasicTools.currentTime() + "." + fileName);
        } else if (osName.toLowerCase().contains("linux")) {
            file = new File("/opt/" + BasicTools.currentTime() + "." + fileName);
        }

        return file;
    }

}
